#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar('\n');
}

typedef struct {int v,w,nxt;}edge;

const int MAXN = 1e5+10;

int n,val[MAXN<<2],lz[MAXN<<2],cover[MAXN<<2],dfn[MAXN],top[MAXN],tot,cnt;
int siz[MAXN],son[MAXN],fa[MAXN],dep[MAXN],ch[MAXN][2],a[MAXN],h[MAXN];
edge e[MAXN<<1];

void link(int x,int y,int w){e[++cnt] = edge{y,w,h[x]};h[x] = cnt;}

void pushdown(int o){
	if(cover[o]){
		cover[o<<1] = cover[o<<1|1] = cover[o];
		lz[o<<1] = lz[o<<1|1] = 0;
		val[o<<1] = val[o<<1|1] = cover[o];
		cover[o] = 0;
	}
	else if(lz[o]){
		if(cover[o<<1]) cover[o<<1] += lz[o];
		else lz[o<<1] += lz[o];
		if(cover[o<<1|1]) cover[o<<1|1] += lz[o];
		else lz[o<<1|1] += lz[o];
		val[o<<1] += lz[o]; val[o<<1|1] += lz[o];
		lz[o] = 0;
	}
}
		
void Cover(int xl,int xr,int v,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r){
		cover[o] = v;lz[o] = 0;
		val[o] = v;
		return;
	}
	int mid = l+r>>1;
	pushdown(o);
	if(xr <= mid) Cover(xl,xr,v,o<<1,l,mid);
	else if(xl > mid) Cover(xl,xr,v,o<<1|1,mid+1,r);
	else Cover(xl,mid,v,o<<1,l,mid),Cover(mid+1,xr,v,o<<1|1,mid+1,r);
	val[o] = max(val[o<<1],val[o<<1|1]);
}

void add(int xl,int xr,int v,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r){
		if(cover[o]) cover[o]+=v;
		else lz[o] += v;
		val[o] += v;
		return;
	}
	int mid = l+r>>1;
	pushdown(o);
	if(xr <= mid) add(xl,xr,v,o<<1,l,mid);
	else if(xl > mid) add(xl,xr,v,o<<1|1,mid+1,r);
	else add(xl,mid,v,o<<1,l,mid),add(mid+1,xr,v,o<<1|1,mid+1,r);
	val[o] = max(val[o<<1],val[o<<1|1]);
}

int query(int xl,int xr,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r) return val[o];
	int mid = l+r>>1;
	pushdown(o);
	if(xr <= mid) return query(xl,xr,o<<1,l,mid);
	else if(xl > mid) return query(xl,xr,o<<1|1,mid+1,r);
	else return max(query(xl,mid,o<<1,l,mid),query(mid+1,xr,o<<1|1,mid+1,r));
}

void dfs(int x,int p){
	dep[x] = dep[p]+1,fa[x] = p,siz[x] = 1;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		a[y] = e[i].w;
		dfs(y,x);
		siz[x] += siz[y];
		if(siz[son[x]] < siz[y]) son[x] = y;
	}
}

void dfs1(int x,int anc){
	top[x] = anc;dfn[x] = ++tot;
	if(son[x]) dfs1(son[x],anc);
	Cover(dfn[x],dfn[x],a[x]);
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == fa[x]||y == son[x]) continue;
		dfs1(y,y);
	}
}

void T_cover(int x,int y,int w){
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		Cover(dfn[top[x]],dfn[x],w);
		x = fa[top[x]];
	}
	if(dfn[x] > dfn[y]) swap(x,y);
	if(dfn[x] != dfn[y]) Cover(dfn[x]+1,dfn[y],w);
}

void T_add(int x,int y,int w){
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		add(dfn[top[x]],dfn[x],w);
		x = fa[top[x]];
	}
	if(dfn[x] > dfn[y]) swap(x,y);
	if(dfn[x] != dfn[y]) add(dfn[x]+1,dfn[y],w);
}

int T_Q(int x,int y){
	int res = 0;
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		res = max(res,query(dfn[top[x]],dfn[x]));
		x = fa[top[x]];
	}
	if(dfn[x] > dfn[y]) swap(x,y);
	if(dfn[x] != dfn[y]) res = max(res,query(dfn[x]+1,dfn[y]));
	return res;
}

int main (){
	n = in;
	for(int i = 1;i < n;i++){
		int x = in,y = in,c = in;
		ch[i][0] = x,ch[i][1] = y;
		link(x,y,c);link(y,x,c);
	}
	dfs(1,0);dfs1(1,1);
	while(1){
		char op[10];
		scanf("%s",op);
		if(op[1] == 'h'){
			int k = in,w = in;
			int x = ch[k][0],y = ch[k][1];
			T_cover(x,y,w);
		}else if(op[1] == 'o'){
			int u = in,v = in,w = in;
			T_cover(u,v,w);
		}else if(op[0] == 'A'){
			int u = in,v = in,w = in;
			T_add(u,v,w);
		}else if(op[0] == 'M'){
			int u = in,v = in;
			int ans = T_Q(u,v);
			write(ans);
		}else break;
	}
	return 0;
}
